import java.lang.reflect.Array;
import java.util.Arrays;

class Student implements Comparable<Student> {
    public String name;
    public int age;
    public int score;

    public Student(String name, int age, int score) {
        this.name = name;
        this.age = age;
        this.score = score;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", score=" + score +
                '}';
    }

    @Override
    public int compareTo(Student o) {//根据成员变量中的：年龄进行比较——如果是比较名字的话怎么办呢？
        //不能使用equals，这个只能比较两个元素是否相等，不能比较其间大小
        if (this.age > o.age){//this指的是调用了compareTo的那个对象
            return 1;
        }else if (this.age < o.age){
            return -1;
        }else {
            return 0;
        }
    /*    if (this.name.compareTo(o.name) > 0) {
            return 1;
        } else if (this.name.compareTo(o.name) < 0) {
            return -1;
        } else {
            return 0;
        }*/
    }
}

public class Test {
    public static void main(String[] args) {//对这个数组排序怎么排？
        Student[] students = new Student[3];
        students[0] = new Student("zhangsan",19,10);
        students[1] = new Student("lisi",24,59);
        students[2] = new Student("wangwu",30,69);
        Arrays.sort(students);
        System.out.println(Arrays.toString(students));
//        System.out.println(students[0].compareTo(students[1]));
        //compareTo返回的是一个整型变量，如果0下标比1下标的元素大，返回一个正数，反之返回一个负数

/*        Arrays.sort(students);
        System.out.println(Arrays.toString(students));*/
    }
/*    public static void main1(String[] args){
        int[] array = {1,3,2,10,5,3,7};
        Arrays.sort(array);
        System.out.println(Arrays.toString(array));
    }*/
}
